package com.yidu.oracle.servlet;

import com.yidu.oracle.model.Member;
import com.yidu.oracle.service.impl.RegDaoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RegDaoServlet",value = "/regDaoServlet")
public class RegDaoServlet extends HttpServlet {
    //将会员信息业务逻辑实例化
    RegDaoService regDaoService=new RegDaoService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //得到登录名
        String loginName =request.getParameter("loginName");

        String memberId=request.getParameter("memberId");
        String sex=request.getParameter("sex");
        String phone=request.getParameter("phone");
        String address=request.getParameter("address");


        //打印出登录名查看
        System.out.println(loginName);
        //调用判断登录名是否存在的方法
        int exist=regDaoService.select(loginName);
        System.out.println(exist);
        if(exist>0){
            response.getWriter().println("<script type='text/javascript'>window.alert('该用户已经存在,请重新注册');</script>");
        }else{
            Member member=new Member();
            member.setMemberId(memberId);
            member.setMemberName(loginName);
            member.setSex(sex);
            member.setPhone(phone);
            member.setAddress(address);
            System.out.println(member.toString());
            regDaoService.deng(member);
        }
    }
}
